/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * LugaresSentado.java
 *
 * Created on 26/06/2012, 18:00:01
 */
package View;

import Controller.Controller;
import Model.Cargo;
import Model.Evento;
import java.awt.Dimension;
import java.awt.Toolkit;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import javax.imageio.ImageIO;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;

/**
 *
 * @author lcc
 */
public class LugaresSentado extends javax.swing.JFrame {

    /**
     * Creates new form LugaresSentado
     */
    Controller controller;
    Evento evento;
    List<JPanel> cadeiras;

    public LugaresSentado(Evento evento) {
        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
        setLocation(screenSize.width / 3, screenSize.height / 3);
        this.evento = evento;
        cadeiras = new ArrayList<JPanel>();
        controller = Controller.getInstance();
        initComponents();
        txtIndisponivel.setVisible(false);
        txtDisponivel.setVisible(false);
    }

    public void verificaDisponibilidade() {
        if (controller.verificaDisponibilidadeCadeira(evento, numero.getSelectedItem().toString(), fileira.getSelectedItem().toString())) {
            txtDisponivel.setVisible(true);
            txtIndisponivel.setVisible(false);
        } else {
            txtDisponivel.setVisible(false);
            txtIndisponivel.setVisible(true);
        }
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        fileira = new javax.swing.JComboBox();
        labelFileira = new javax.swing.JLabel();
        labelNumero = new javax.swing.JLabel();
        numero = new javax.swing.JComboBox();
        canvas1 = new java.awt.Canvas();
        btnConfirmar = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        txtIndisponivel = new javax.swing.JLabel();
        txtDisponivel = new javax.swing.JLabel();
        voltarButton = new javax.swing.JButton();
        grid = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        fileira.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "A", "B", "C", "D", "E", "F", "G", "H", "I", "J" }));
        fileira.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                fileiraActionPerformed(evt);
            }
        });

        labelFileira.setText("Fileira");

        labelNumero.setText("Numero");

        numero.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12" }));
        numero.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                numeroActionPerformed(evt);
            }
        });

        btnConfirmar.setText("Confirmar");
        btnConfirmar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnConfirmarActionPerformed(evt);
            }
        });

        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 24)); // NOI18N
        jLabel1.setText("Comprar Ingresso");

        txtIndisponivel.setFont(new java.awt.Font("Tahoma", 1, 12));
        txtIndisponivel.setForeground(new java.awt.Color(204, 0, 0));
        txtIndisponivel.setText("Cadeira Indisponível");

        txtDisponivel.setFont(new java.awt.Font("Tahoma", 1, 12));
        txtDisponivel.setForeground(new java.awt.Color(0, 204, 0));
        txtDisponivel.setText("Cadeira Disponível");

        voltarButton.setText("Voltar");
        voltarButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                voltarButtonActionPerformed(evt);
            }
        });

        grid.setIcon(new javax.swing.ImageIcon("C:\\Users\\Rodrigo\\Documents\\UFF\\2012.1\\ES\\casa-de-show\\CasaDeShow\\gridCadeiras.png")); // NOI18N

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(478, 478, 478)
                        .addComponent(canvas1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(67, 67, 67)
                        .addComponent(grid))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(356, 356, 356)
                        .addComponent(jLabel1))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(140, 140, 140)
                        .addComponent(voltarButton)
                        .addGap(45, 45, 45)
                        .addComponent(labelFileira)
                        .addGap(76, 76, 76)
                        .addComponent(fileira, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(45, 45, 45)
                        .addComponent(labelNumero)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(numero, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(33, 33, 33)
                        .addComponent(btnConfirmar)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(txtDisponivel)
                            .addComponent(txtIndisponivel))))
                .addContainerGap(73, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(31, 31, 31)
                .addComponent(jLabel1)
                .addGap(30, 30, 30)
                .addComponent(grid)
                .addGap(56, 56, 56)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(txtDisponivel)
                        .addComponent(txtIndisponivel))
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(fileira, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(labelFileira)
                        .addComponent(numero, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(labelNumero)
                        .addComponent(btnConfirmar)
                        .addComponent(voltarButton)))
                .addGap(194, 194, 194)
                .addComponent(canvas1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnConfirmarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnConfirmarActionPerformed
        // TODO add your handling code here:
        if (!controller.vendeIngressoCadeira(fileira.getSelectedItem().toString(), numero.getSelectedItem().toString(), evento)) {
            JOptionPane.showMessageDialog(null, "Cadeira ocupada! Por favor, escolha outra.", "Erro", JOptionPane.ERROR_MESSAGE);
        } else {
            JOptionPane.showMessageDialog(null, "Compra efetuada com sucesso!", "Sucesso", JOptionPane.INFORMATION_MESSAGE);
        }
    }//GEN-LAST:event_btnConfirmarActionPerformed

    private void numeroActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_numeroActionPerformed
        // TODO add your handling code here:
        verificaDisponibilidade();
    }//GEN-LAST:event_numeroActionPerformed

    private void fileiraActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_fileiraActionPerformed
        // TODO add your handling code here:
        verificaDisponibilidade();

    }//GEN-LAST:event_fileiraActionPerformed

    private void voltarButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_voltarButtonActionPerformed
        if (controller.getCargo() == Cargo.GERENTE) {
            VerEventoGerente veg = new VerEventoGerente(evento);
            veg.setVisible(true);
            this.setVisible(false);
        } else {
            VerEventoBilheteria veb = new VerEventoBilheteria(evento);
            veb.setVisible(true);
            this.setVisible(false);
        }
    }//GEN-LAST:event_voltarButtonActionPerformed
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new LugaresSentado(new Evento()).setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnConfirmar;
    private java.awt.Canvas canvas1;
    private javax.swing.JComboBox fileira;
    private javax.swing.JLabel grid;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel labelFileira;
    private javax.swing.JLabel labelNumero;
    private javax.swing.JComboBox numero;
    private javax.swing.JLabel txtDisponivel;
    private javax.swing.JLabel txtIndisponivel;
    private javax.swing.JButton voltarButton;
    // End of variables declaration//GEN-END:variables
}
